home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
basic
/
vbmake.exe
/
MM.BAS
< prev
next >
Wrap
BASIC Source File
|
1993-05-05
|
20KB
|
627 lines
' Billy Dennigan MBN International Systems Ltd March 1993
' Compuserve ID 100014,2700
' Makefile Generator
' This program generates a simple makefile by copying the MS Basic .MAK file
' to a file usable by the NMAKE utility, with the appropriate dependencies
' and switches.
' If you find this program useful, please acknowledge by E-Mail
' Example .INI files are included for VBDOS and BC7
' These should be changed to suit your personal configuration
' MM /? for help
DECLARE SUB IncludeFiles (Filename$, OutFile%)
DECLARE SUB LoadList (ListFile$, ObjList$(), NumObjs%)
DECLARE SUB ReadIni (IniFile$, Options() AS ANY)
DECLARE SUB ShowHelp ()
DECLARE SUB Substitute (Change$, ObjList$())
DECLARE FUNCTION CmdParam$ (Cmd$, name$)
DECLARE FUNCTION GetValue$ (Num%, Ini() AS ANY)
DECLARE FUNCTION RemoveExt$ (Filename$)
DECLARE FUNCTION RemovePath$ (Filename$)
'============== one of these per entry in the .INI file ==============
TYPE IniRec
Index AS INTEGER
Value AS STRING * 50
END TYPE
CONST FALSE = 0, TRUE = NOT FALSE
CONST NumOfSources = 128 ' max. number of sources for an EXE file
CONST MaxIniLines = 128 ' max. number of entries in .INI file
CONST NumSettings = 8 ' change this if you add any settings to DATA
REDIM ObjList$(NumOfSources)
REDIM Inis(MaxIniLines) AS IniRec
PRINT
PRINT " Makefile Generator. Version 2.0 Mar.1993"
PRINT " Billy Dennigan, MBN International Systems Ltd."
PRINT
Cmd$ = COMMAND$
'========== HELP FACILITY ==========
IF INSTR(Cmd$, "/?") THEN
CALL ShowHelp
END
END IF
'========= get the target filename if necessary ============
IF Cmd$ = "" THEN
PRINT "Target File :";
INPUT TargetFile$
ELSE
TargetFile$ = Cmd$
END IF
IF LEN(TargetFile$) = 0 THEN END
'================ GET THE NAME OF THE .INI FILE ===================
IniFile$ = "MM.INI"
DO UNTIL LEN(DIR$(IniFile$))
PRINT "Cannot find MM Initialisation file "; IniFile$;
PRINT " Please enter new file spec: ";
INPUT IniFile$
IF LEN(IniFile$) = 0 THEN CLOSE : END
LOOP
'============ LOAD DATA INTO ARRAY OF RECORDS inis() ==============
CALL ReadIni(IniFile$, Inis())
'truncate the extension from the target file if it was specified
TargetFile$ = UCASE$(TargetFile$)
TargetFile$ = RemoveExt$(TargetFile$)
MakeFile$ = TargetFile$ ' Makefile to be generated
RespFile$ = TargetFile$ + ".LNK" ' response file for linker
ListFile$ = TargetFile$ + ".MAK" ' input list of required files
Tab$ = CHR$(9)
'--- load in the list of Modules -----
CALL LoadList(ListFile$, ObjList$(), NumObjs%)
MkeFile% = FREEFILE
OPEN MakeFile$ FOR OUTPUT AS #MkeFile% ' MakeFile
LnkFile% = FREEFILE
OPEN RespFile$ FOR OUTPUT AS #LnkFile% ' Response file
mmddyy$ = DATE$
ddmmyy$ = MID$(DATE$, 4, 2) + "/" + LEFT$(DATE$, 2) + "/" + RIGHT$(DATE$, 2)
PRINT #MkeFile%, "# Makefile for "; TargetFile$
PRINT #MkeFile%, "# Date written: "; ddmmyy$; " at "; LEFT$(TIME$, 5);
PRINT #MkeFile%, " by Makefile Generator [MM] Version 1.10"
PRINT #MkeFile%, "# .INI file used was "; IniFile$
PRINT #MkeFile%, "# Billy Dennigan, MBN International Systems Ltd."
PRINT #MkeFile%, "# Uses response file "; RespFile$; " for Linker"
PRINT #MkeFile%, "#"
'------ compiler is Setting 1 -----
DO
Tmp$ = GetValue$(1, Inis())
TmpLen% = LEN(Tmp$)
IF TmpLen% THEN Compiler$ = Tmp$
LOOP WHILE TmpLen%
'------ linker is Setting 2 ------
DO
Tmp$ = GetValue$(2, Inis())
TmpLen% = LEN(Tmp$)
IF TmpLen% THEN Linker$ = Tmp$
LOOP WHILE TmpLen%
'--------- extract all the compiler flags (Setting 3) ---------
DO
ThisFlag$ = GetValue$(3, Inis())
CompFlag$ = CompFlag$ + ThisFlag$
LOOP WHILE LEN(ThisFlag$)
'--------- extract all the linker flags (Setting 4) -----------
DO
ThisFlag$ = GetValue$(4, Inis())
LinkFlag$ = LinkFlag$ + ThisFlag$
LOOP WHILE LEN(ThisFlag$)
'--------- get filename substitutions (Setting 6) ------------
DO
Change$ = GetValue$(6, Inis())
IF LEN(Change$) = 0 THEN EXIT DO
CALL Substitute(Change$, ObjList$())
LOOP
'------ INCLUDEs is Setting 7 ------
'At this point, just determine whether or not the user wants INCLUDED files
' put into the dependencies list. Will process them later on.
DO
Tmp$ = GetValue$(7, Inis())
TmpLen% = LEN(Tmp$)
IF TmpLen% THEN GetIncludes$ = UCASE$(Tmp$)
LOOP WHILE TmpLen%
IF INSTR(GetIncludes$, "TRUE") THEN GetIncludes% = -1
'------ ObjDir is Setting 8 ------
' this can be used to specify a directory where all .OBJ files are to be put
DO
Tmp$ = GetValue$(8, Inis())
TmpLen% = LEN(Tmp$)
IF TmpLen% THEN
ObjDir$ = UCASE$(Tmp$)
ObjDir% = TRUE
END IF
LOOP WHILE TmpLen%
'----- format the path so that it can be used to make up a valid filename
LastChar$ = RIGHT$(ObjDir$, 1)
IF LastChar$ <> ":" AND LastChar$ <> "\" THEN ObjDir$ = ObjDir$ + "\"
PRINT #MkeFile%, "# Can change your source file and compilers,etc here:"
PRINT #MkeFile%, ""
PRINT #MkeFile%, "EXE = "; TargetFile$
PRINT #MkeFile%, "COMPILE = "; Compiler$
PRINT #MkeFile%, "LINK = "; Linker$
PRINT #MkeFile%, "COMPFLAGS = "; CompFlag$
PRINT #MkeFile%, "LINKFLAGS = "; LinkFlag$
PRINT #MkeFile%,
PRINT #MkeFile%, "ALL : $(EXE).EXE"
'=========== DEPENDENCIES FOR THE .OBJ FILE (COMPILATION PHASE) ===========
FOR i% = 1 TO NumObjs%
Filename$ = ObjList$(i%)
Stem$ = RemoveExt$(Filename$)
'---------- If a path was specified for the .OBJ files ---------
IF ObjDir% THEN Stem$ = ObjDir$ + RemovePath$(Stem$)
PRINT Filename$;
PRINT #MkeFile%, ""
PRINT #MkeFile%, Stem$; ".OBJ : ";
PRINT #MkeFile%, Filename$;
IF GetIncludes% THEN
'------ Find which files have been INCLUDEd in this one ------
Col% = POS(0): Row% = CSRLIN
COLOR 15
PRINT " Scanning...";
COLOR 7
CALL IncludeFiles(Filename$, MkeFile%)
LOCATE Row%, Col%: PRINT " ";
LOCATE Row%, Col%
END IF
PRINT
PRINT #MkeFile%,
PRINT #MkeFile%, Tab$; "$(COMPILE) $(COMPFLAGS) "; Filename$; " "; Stem$; ".OBJ ;"
NEXT i%
'========== DEPENDENCIES FOR THE .EXE FILE i.e. THE LINK PHASE =============
PRINT #MkeFile%, ""
PRINT #MkeFile%, "$(EXE).EXE : ";
FOR i% = 1 TO NumObjs%
ObjFile$ = RemoveExt$(ObjList$(i%)) + ".OBJ "
IF ObjDir% THEN ObjFile$ = ObjDir$ + RemovePath$(ObjFile$)
PRINT #MkeFile%, ObjFile$; " ";
NEXT i%
'=============== THE .EXE IS ALSO DEPENDENT ON .LIB FILES ==================
Lib$ = GetValue$(0, Inis()) ' reset internal pointers
DO
Lib$ = GetValue$(5, Inis())
IF LEN(Lib$) THEN PRINT #MkeFile%, UCASE$(Lib$); " "; ELSE EXIT DO
LOOP
PRINT #MkeFile%, ""
PRINT #MkeFile%, Tab$; "$(LINK) $(LINKFLAGS) ";
PRINT #MkeFile%, "@"; RespFile$
'=============== GENERATE THE LINKER RESPONSE FILE ===================
'--------------- DEAL WITH ALL NECESSARY .OBJ FILES ------------------
FOR i% = 1 TO NumObjs%
ObjFile$ = RemoveExt$(ObjList$(i%)) + ".OBJ "
'--- temporary: leave the OBJ files in current dir ----
IF ObjDir% THEN ObjFile$ = ObjDir$ + RemovePath$(ObjFile$)
PRINT #LnkFile%, ObjFile$; " +"
NEXT i%
'--------------- TERMINATE THE LIST OF .OBJ FILES ---------------------
PRINT #LnkFile%,
'--------------- SPECIFY THE NAME OF THE .EXE FILE --------------------
PRINT #LnkFile%, TargetFile$; ".EXE"
'--------------- SPECIFY THE NAME OF THE .MAP FILE --------------------
PRINT #LnkFile%, "NUL.MAP"
'--------------- GENERATE THE LIST OF LIBRARY FILES -------------------
Lib$ = GetValue$(0, Inis()) ' reset internal pointers
DO
PRINT "Libraries : ";
Lib$ = GetValue$(5, Inis())
'when "LIB=;" is encountered, no more libraries are included.
SemiColon% = INSTR(Lib$, ";")
IF SemiColon% THEN
Lib$ = LEFT$(Lib$, SemiColon%)
IF Lib$ = ";" THEN PRINT : EXIT DO
END IF
IF LEN(Lib$) = 0 THEN ' if the .INI file has no more libs,
INPUT "", Lib$ ' then get one from the user
ELSE
PRINT Lib$; "+" ' this is the lib read from the .INI file
END IF
IF LEN(Lib$) = 0 THEN E